#!/usr/bin/env python
#coding=utf-8

import wx

class Menu(object):
    ''' Main application menu. '''

    def __init__(self, view):
        ''' Awaiting the view object. '''

        self.view = view

    def create_menu(self):
        ''' Create our applications main menu. '''

        menuBar = wx.MenuBar()
        menuBar.Append(self.create_fileMenu(),'&File')
        menuBar.Append(self.create_optionMenu(),'&Options')
        menuBar.Append(self.create_helpMenu(),'&Help')
        self.view.SetMenuBar(menuBar)

    def create_fileMenu(self):
        ''' Create the entries for the options menu. '''

        fileMenu = wx.Menu()

        self.view.importItem = wx.MenuItem(fileMenu, -1, text='&Import')
        self.view.exportItem = wx.MenuItem(fileMenu,-1, text='&Export')
        self.view.quitItem = wx.MenuItem(fileMenu,-1, text='&Quit')

        self.populate_menu(fileMenu,self.view.importItem,self.view.exportItem,
            self.view.quitItem)
        return fileMenu

    def create_optionMenu(self):
        ''' Create the entries for the options menu. '''

        optionMenu = wx.Menu()
        self.view.categoryItem = wx.MenuItem(optionMenu, -1, text='&Category')
        self.view.preferencesItem=wx.MenuItem(optionMenu,-1,
            text='&Preferences')

        self.populate_menu(optionMenu, self.view.categoryItem,
            self.view.preferencesItem)
        return optionMenu

    def create_helpMenu(self):
        ''' Create the entries for the help menu. '''

        helpMenu = wx.Menu()
        self.view.aboutItem = wx.MenuItem(helpMenu, wx.NewId(),
                                            text = '&About')
        self.populate_menu(helpMenu,self.view.aboutItem)
        return helpMenu

    def populate_menu(self, menu, *lst):
        ''' Append a list of wx.MenuItem elements at a menu. '''

        for eachMenu in lst:
            menu.AppendItem(eachMenu)